<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>出库批次管理</title>
		<script type="text/javascript">
		$(function() {
			$("#queryForm").validate();
			$("#_fromDate").datepicker({ format:'yyyy-mm-dd'});
			$("#_toDate").datepicker({ format:'yyyy-mm-dd'});
	  });

	function ajaxPutShippedBatch(item) {
		$.ajax({
			type : 'post',
			url : '${ctx}/focusShippedBatch/ajaxPutShippedBatch',
			data : 'backupTaskCode=' + item,
			dataType : 'json',
			success : function(data) {
				$("#content").html(data.content);
				$("#message").show();
			},

			error : function() {
				alert("服务器错误！！！");
			}
		});
	}
	
	 
	  function ajaxHomeAreaGroup(item) {
			customerCode=item.value;
			$.ajax({
						type : 'post',
						url : '${ctx}/areaGroup/ajaxHomeAreaGroup',
						data : 'customerCode=' + customerCode,
						dataType : 'json',
						success : function(data) {
						  var tempString="";
							if (data.status == "1") {
								$.each(data.content,function(i){
								    tempString+="<option value="+data.content[i].groupCode+">"+data.content[i].groupName;
								});
							}else {
								alert(data.content);
							}
	                  $("#areaGroupCodeSingle").html(tempString);
	                  $("#areaGroupCodeSingle").trigger("chosen:updated");
						},
						error : function() {
							alert_message("系统错误！","请检查网络连接是否正常！","error",10000);
						}
					});
		}

</script>
	</head>
	<body>
		<div id="message" class="alert alert-success" style="display: none;">
			<span id="content"></span>
		</div>
		
		<form class="form-search" id="queryForm" method="post" action="${ctx}/focusShippedBatch/batchLists" style="margin-top: 10px;">
	     <table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
		<thead>
			<th style="vertical-align: middle; color: white; " colspan="1" bgcolor="#999 ">条件查询</th>
		</thead>
		<tr >
		   <td>
		      <label style="margin-left: 10px;"><b>商家:</b></label>
				<select class="input-medium required"  id="_customerCode" name="_customerCode"  value="${param._customerCode}" style="width: 95px;" onchange="ajaxHomeAreaGroup(this);ajaxAreaGroup(this,'_warehouseCode');">
						<c:forEach items="${customers}" var="o">
							<option value="${o.customerCode}" <c:if test="${param._customerCode eq o.customerCode }">selected=selected</c:if>>${o.customerName}</option>
						</c:forEach>
				</select> 
 			 	<label style="margin-left: 10px;"><b>仓库:</b></label> 
 				 <select  name="_warehouseCode"  id="_warehouseCode" value="${param._warehouseCode}"  class="input-medium" style="width: 120px;"> 
					
 					<c:if test="${wmList eq null }">
							<c:forEach items="${object.restAreaGroupDtos}" var="obj">
								<option value="${obj.areagroupCode}" <c:if test="${areaGroupCode eq obj.areagroupCode}">selected</c:if>> ${obj.areagroupName}
								</option>
							</c:forEach>
				   </c:if>
				   <c:if test="${object eq null }">
				     <c:forEach items="${wmList}" var="wm">
						<option value="${wm.groupCode}" <c:if test="${param._warehouseCode eq wm.groupCode}">selected=selected</c:if> >${wm.groupName}</option>
					  </c:forEach>
				   </c:if>
 				</select>
				 <label><b>网点:</b></label>
						<select name="_areaGroupCode" class="input-medium" style="width: 160px;" id="areaGroupCodeSingle">
							<c:forEach items="${areaGroups}" var="obj">
								<option value="${obj.groupCode}" <c:if test="${areaGroupCode eq obj.groupCode}">selected</c:if>>${obj.groupName}
								</option>
							</c:forEach>
						</select>
				 <label style="margin-left: 10px;"><b>类型:</b></label>
				 <select class="input-medium"  id="_batchType" name="_batchType" style="width: 70px;">
				        <option value="" <c:if test="${param._pickType eq ''}">selected="selected"</c:if>>全选</option>
				        <option value="single" <c:if test="${param._pickType eq 'single'}">selected="selected"</c:if>>单件</option>
				        <option value="multiple" <c:if test="${param._pickType eq 'multiple'}">selected="selected"</c:if>>多件</option>
				 </select>
			 	
				
			    
		   </td>
		</tr>
		<tr>
		<td>
			<label style="margin-left: 10px;"><b>时间：</b></label> 
			 	<input type="text" name="_fromDate" id="_fromDate"  class="input-small" value="${param._fromDate}" style="margin-left: -10px;width: 80px;" >
			 	<label><b>至：</b></label> 
			 	<input type="text" name="_toDate" id="_toDate" class="input-small" value="${param._toDate}" style="margin-left: -10px;width: 80px;" >
			 	
		   
		        <button class="btn btn-info" type="submit" style="margin-left: 10px;">搜索</button>
			
			
		</td>
		</tr>
		
	</table>
	 </form>
		<table id="contentTable"
			class="table table-striped table-bordered table-condensed">
			<thead>
				<tr>
					<th>
						编号
					</th>
					<th>
						箱子数量
					</th>
					<!--<th>
						生成日期
					</th>
					<th>
						处理日期
					</th>
					--><th>
						订单数量
					</th>
					<th>
						商品数量
					</th>
					<th>
						商品种类
					</th>
					<th>
						类型
					</th>
					
					<th>网点</th>
					<th>
						操作人
					</th>
					<th>
						状态
					</th>

				</tr>
			</thead>
			<tbody>
				<c:if test="${status eq 0 }">
					<c:forEach items="${shippedBatchs.content}" var="obj">
						<tr>
							<td>
								${obj.batchCode }
							</td>
							<td>
								<c:choose>
									<c:when test="${obj.boxQty ne 0 }">
										<a href="${ctx }/shippedBox/showBoxs/${obj.batchCode}">${obj.boxQty
											}</a>
									</c:when>
									<c:otherwise>
                                        ${obj.boxQty }
                                    </c:otherwise>
								</c:choose>


							</td>
							<td>
								<a href="${ctx }/backupTask/showOrdenos/${obj.backupTaskCode}">${obj.ordenoQty}</a>
							</td>
							<td>
								${obj.skuQty }
							</td>
							<td>
								${obj.skuType }
							</td>
							<td>
								<c:if test="${obj.type eq 'single' }">
							     单件
							</c:if>
								<c:if test="${obj.type eq 'multiple' }">
							  多件
							</c:if>
								
							</td>

							
							<td>
						 ${obj.areaGroupName }
						</td>
							<td>
								${obj.username }
							</td>
							<td>


								<c:if test="${obj.boxStatus eq 'pending'}">
									<a href="${ctx }/focusShippedBatch/shippedBoxSkus/${obj.batchCode}"
										class="btn btn-success">开始装箱</a>
								</c:if>

								<c:if test="${obj.boxStatus eq 'finish'}">
									<c:if test="${obj.status eq 'pending' }">
										<a
											href="javascript:ajaxPutShippedBatch('${obj.backupTaskCode}');"
											class="btn btn-danger">推送数据</a>
									</c:if>
									<c:if test="${obj.status eq 'finish' }">
										<a
											href="javascript:ajaxPutShippedBatch('${obj.backupTaskCode}');"
											class="btn btn-inverse">重新推送</a>
									</c:if>
								</c:if>
								<c:if test="${obj.type eq 'forward' }">
									<a
										href="${ctx }/printBackupTask/printInit/${obj.backupTaskCode}"
										class="btn btn-primary">重新打印</a>
								</c:if>
								<a class="btn"
									href="${ctx}/focusShippedBatch/exportExcel/${obj.backupTaskCode}">导出</a>

							</td>

						</tr>
					</c:forEach>
				</c:if>
				<c:if test="${status eq 1 }">
					<c:forEach items="${shippedBatchs}" var="obj">
						<tr>
							<td>
								${obj.batchCode }
							</td>
							<td>
								<c:choose>
									<c:when test="${obj.boxQty ne 0 }">
										<a href="${ctx }/shippedBox/showBoxs/${obj.batchCode}">${obj.boxQty
											}</a>
									</c:when>
									<c:otherwise>
                                        ${obj.boxQty }
                                    </c:otherwise>
								</c:choose>
							</td>
							<td>
								<a href="${ctx }/backupTask/showOrdenos/${obj.backupTaskCode}">${obj.ordenoQty
									}</a>
							</td>
							<td>
								${obj.skuQty }
							</td>
							<td>
								${obj.skuType }
							</td>
							<td>
								<c:if test="${obj.type eq 'single' }">
							                      单件
							    </c:if>
								<c:if test="${obj.type eq 'multiple' }">
							                       多件
						     	</c:if>
								<c:if test="${obj.type eq 'forward' }">
							                       中转发
							    </c:if>
							</td>
							
							<td>
						 ${obj.areaGroupName }
						</td>
							<td>
								${obj.username }
							</td>
							<td>

								<c:if test="${obj.boxStatus eq 'pending'}">
									<a href="${ctx }/focusShippedBatch/shippedBoxSkus/${obj.batchCode}"
										class="btn btn-success">开始装箱</a>
								</c:if>

								<c:if test="${obj.boxStatus eq 'finish'}">
									<c:if test="${obj.status eq 'pending' }">
										<a
											href="javascript:ajaxPutShippedBatch('${obj.backupTaskCode}');"
											class="btn btn-danger">推送数据</a>
									</c:if>
									<c:if test="${obj.status eq 'finish' }">
										<a
											href="javascript:ajaxPutShippedBatch('${obj.backupTaskCode}');"
											class="btn btn-inverse">重新推送</a>
									</c:if>
								</c:if>
								<c:if test="${obj.type eq 'forward' }">
									<a
										href="${ctx }/printBackupTask/printInit/${obj.backupTaskCode}"
										class="btn btn-primary">重新打印</a>
								</c:if>

								<a class="btn"
									href="${ctx}/focusShippedBatch/exportExcel/${obj.backupTaskCode}">导出</a>
							</td>

						</tr>
					</c:forEach>
				</c:if>
			</tbody>
		</table>
		<c:if test="${status eq 0 }">
			<tags:pagination page="${shippedBatchs}" paginationSize="5" />
		</c:if>
	</body>
</html>